#ifndef _FeedFrame_H_
#define _FeedFrame_H_


#include "kfifo.h"


#define FEED_FRAME_DATA_SIZE                512


typedef enum {
    FEED_FRAME_SUCCEED = 0,
    FEED_FRAME_ERROR_ACCESS,                /* 无权限 */
    FEED_FRAME_ERROR_LENGTH,                /* 长度错误 */
    FEED_FRAME_ERROR_DATAS,                 /* 数据内容错误 */
    FEED_FRAME_ERROR_DATAS_TYPE,            /* 数值类型错误 */
    FEED_FRAME_ERROR_DATAS_MAX,             /* 数值过大错误 */
    FEED_FRAME_ERROR_DATAS_MIN,             /* 数值过小错误 */
}FeedFrameErrorEnum;


typedef enum {
    FEED_FRAME_TYPE_INT = 0,                /* 整型 */
    FEED_FRAME_TYPE_FLOAT,                  /* 浮点型 */
    FEED_FRAME_TYPE_STRING,                 /* 字符型 */
    FEED_FRAME_TYPE_RAW,                    /* 数据型 */
    FEED_FRAME_TYPE_NULL,                   /* 无数据 */
}FeedFrameTypeEnum;


typedef struct{
    uint16_t ID             : 12;           /* ID */
    uint16_t reserved       : 2;            /* 预留 */
    uint16_t response       : 1;            /* 是否为响应 */
    uint16_t get            : 1;            /* 0:更新、1:请求 */
    uint16_t length         : 12;           /* 数据长度 */
    uint16_t type           : 4;            /* 0:int、1:float、2:string、3:raw */
    uint8_t datas[FEED_FRAME_DATA_SIZE];    /* 数据 */
}FeedFrameType;


extern KFIFO g_typekFIFOFrame;


int8_t cFeedFrameAddx(uint16_t usID, uint8_t ucType, int32_t iValue, float fValue, double dValue, void *pvDatas, int32_t iLength);
#define cFeedFrameAddInt(usID, iValue)              cFeedFrameAddx((usID), FEED_FRAME_TYPE_INT, iValue, 0.0f, 0.0, NULL, 0)
#define cFeedFrameAddFloat(usID, fValue)            cFeedFrameAddx((usID), FEED_FRAME_TYPE_FLOAT, 0, fValue, fValue, NULL, 0)
#define cFeedFrameAddDouble(usID, dValue)           cFeedFrameAddx((usID), FEED_FRAME_TYPE_FLOAT, 0, dValue, dValue, NULL, 0)
#define cFeedFrameAddString(usID, pvDatas)          cFeedFrameAddx((usID), FEED_FRAME_TYPE_STRING, 0, 0.0f, 0.0, (pvDatas), strlen((char *)pvDatas))
#define cFeedFrameAddRaw(usID, pvDatas, iLength)    cFeedFrameAddx((usID), FEED_FRAME_TYPE_RAW, 0, 0.0f, 0.0, (pvDatas), (iLength))

int8_t cFeedFrameDecode(uint8_t ucType, void *pvDatas, int32_t iSizeIn);


#endif
